package xyz.hubery.controller;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xyz.hubery.domain.CashRecharge;
import xyz.hubery.domain.CoinRecharge;
import xyz.hubery.domain.CoinWithdraw;
import xyz.hubery.model.R;
import xyz.hubery.service.CashRechargeService;
import xyz.hubery.service.CoinRechargeService;

@RestController
@RequestMapping("/coinRecharges")
@Api(tags = "充币记录")
public class CoinRechargeController {

    @Autowired
    private CoinRechargeService coinRechargeService;

    @GetMapping("/records")
    @ApiOperation("分页查询充币记录")
    public R<Page<CoinRecharge>> findByPage(Long userId,
                                            String userName,
                                            String mobile,
                                            Byte status,
                                            Integer numMin,
                                            Integer numMax,
                                            String startTime,
                                            String endTime
            , Page<CoinRecharge> page) {
        Page<CoinRecharge> coinRechargePage = coinRechargeService.findPage(userId, userName, mobile, status, numMin, numMax, startTime, endTime,  page);
        return R.ok(coinRechargePage);
    }

    @GetMapping("/user/record")
    @ApiOperation("分页查询用户充币记录")
    public R<Page<CoinRecharge>> findUserRechargePage(@RequestParam(required = false)Long coinId,Page<CoinRecharge> page) {
        Long userId = Long.valueOf(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString());
        page.addOrder(OrderItem.desc("last_update_time"));
        Page<CoinRecharge> pageData =  coinRechargeService.findCoinRechargePage(userId, coinId, page);
        return R.ok(pageData);
    }
}
